package com.infore.qualityControl.export.policy.strategy.concreteStrategy;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.infore.qualityControl.export.policy.bo.ExportParamBo;
import com.infore.qualityControl.export.policy.strategy.Strategy;
import com.infore.qualityControl.export.util.ExportUtil;
import com.infore.qualityControl.service.IQualityAnalysisService;
import com.infore.qualityControl.util.ObjectMapperUtil;
import com.infore.qualityControl.util.ResultEntity;

@Service("QUALITY_CONTROLLER_EXAMINE")
public class QualityControlExamineStrategy implements Strategy {

	@Autowired
	IQualityAnalysisService IQualityAnalysisService;

	@Autowired
	ObjectMapperUtil ObjectMapperUtil;

	@Override
	public byte[] doExcelStrategy(List<Map<String, Object>> list, ExportParamBo exportParamBo) throws Exception {
		list = this.doData(list, exportParamBo);
		return ExportUtil.exportExcel(exportParamBo.getRequest(), list, exportParamBo.getHeaderProp(),
				exportParamBo.getPattern());
	}

    @Override
    public byte[] doPdfStrategy(List<Map<String, Object>> list, ExportParamBo exportParamBo) throws Exception {
        list = this.doData(list, exportParamBo);
        return ExportUtil.exportPdf(exportParamBo.getRequest(), list, exportParamBo.getHeaderProp(),
                exportParamBo.getPattern());
    }

    @Override
    public byte[] doWordStrategy(List<Map<String, Object>> list, ExportParamBo exportParamBo) throws Exception {
        list = this.doData(list, exportParamBo);
        return ExportUtil.exportWord(exportParamBo.getRequest(), list, exportParamBo.getHeaderProp(),
                exportParamBo.getPattern());
    }

    @Override
    public List<Map<String, Object>> doData(List<Map<String, Object>> list, ExportParamBo exportParamBo) throws Exception {
        ResultEntity resultEntity = IQualityAnalysisService
                .qualityControllerExamineData(exportParamBo.getQualityParamAnalysisBo(), exportParamBo.getPageObject());
        list = ObjectMapperUtil.convertListMap(resultEntity);
        return list;
    }

}
